﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using eTruck.Helpers;
namespace eTruck.Views.Route
{
    public partial class Form : System.Web.UI.Page
    {
        protected string returnValue = string.Empty;

        BLL.Route bll = new BLL.Route();
        protected void Page_Load(object sender, EventArgs e)
        {
            string type = System.Web.HttpUtility.UrlDecode(Request["Type"]);
            if (type == "Save")
            {
                Save();
            }
           
        }

        private void Save()
        {
            Model.Route model = new Model.Route();

            string OLDFormTypeID = System.Web.HttpUtility.UrlDecode(Request["OLDFormTypeID"]);
              string OLDProcessID = System.Web.HttpUtility.UrlDecode(Request["OLDProcessID"]);
              string OLDNextProcessID = System.Web.HttpUtility.UrlDecode(Request["OLDNextProcessID"]);



            model.FormTypeID =int.Parse(System.Web.HttpUtility.UrlDecode(Request["FormTypeID"]));

            model.ProcessID = int.Parse( System.Web.HttpUtility.UrlDecode(Request["ProcessID"]).ToString());
            model.NextProcessID = int.Parse(System.Web.HttpUtility.UrlDecode(Request["NextProcessID"]).ToString());




            try
            {
                bool result = false;
                if (OLDFormTypeID.Length == 0)
                {
                    //create new User
                    result = bll.Add(model);
                }
                else
                {
                    //update User Info...                   
                    result = bll.Delete(Convert.ToInt32(OLDFormTypeID), Convert.ToInt32(OLDProcessID), Convert.ToInt32(OLDNextProcessID));
                    result = bll.Add(model);
                }
                if (result)
                {
                    returnValue = "True";
                }
                else
                {
                    returnValue = "False";
                }
            }
            catch (Exception ex)
            {
                returnValue = ex.Message;
            }
        }

     
    }
}

